﻿<template>
  <a-modal
    :title="title"
    width="40%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
   <a-card :bordered="false">
    <a-form :form="form">
      <a-form-item label="文件上传" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <!--v-model为图片连接地址(可传单个或数组),maxCount为最大上传数:默认为1-->
        <c-upload-file v-model="entity.Doc" :maxCount="1"></c-upload-file>
      </a-form-item>
      <!-- <a-form-item label="获取图片链接" :labelCol="labelCol" :wrapperCol="wrapperCol">
        <a-button @click="setFile()">设置文件链接</a-button>
        <a-button @click="getFileUrls()">获取文件链接</a-button>
      </a-form-item> -->
    </a-form>
  </a-card>
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="保险名称" prop="Name">
          <a-input v-model="entity.Name" autocomplete="off" />
        </a-form-model-item>
        <!-- <a-form-model-item label="条款文件" prop="Doc">
          <a-input v-model="entity.Doc" autocomplete="off" />
        </a-form-model-item> -->
        <a-form-model-item label="保险售价" prop="SaleAmount">
          <a-input v-model="entity.SaleAmount" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="理赔金额" prop="ClaimAmount">
          <a-input v-model="entity.ClaimAmount" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="险种备注" prop="Desc">
          <a-input v-model="entity.Desc" autocomplete="off" />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import CUploadFile from '@/components/CUploadFile/CUploadFile'


export default {
  components: {
    CUploadFile
  },
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: '',
      form: this.$form.createForm(this),
      labelCol: { xs: { span: 24 }, sm: { span: 7 } },
      wrapperCol: { xs: { span: 24 }, sm: { span: 13 } },
      entity: { File: require('@/assets/logo.png') }
    }
  },
  methods: {
    // getFileUrls() {
    //   console.log(this.entity)
    // },
    // setFile() {
    //   this.entity = { File: require('@/assets/logo.png') }
    // },
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()

      if (id) {
        this.loading = true
        this.$http.post('/NIns/NInsurance/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/NIns/NInsurance/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
